package com.jelica.videoteka.pages;

import java.security.Security;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;
import com.jelica.videoteka.interfaces.PomocniKorisnikI;
import com.jelica.videoteka.service.PomocniKorisniksI;

public class Login {
	private String userName;
	@Property
    private String password;
    
	@Inject
	@Property
	private PomocniKorisniksI pomocniKorisniks;

	@SessionState
    private PomocniKorisnikI pomocniKorisnik;

	Object onSubmitFromLoginForm() {
		System.out.println("U login formi - event hendler");
		Class nextPage = null;
		PomocniKorisnikI authenticatedUser = com.jelica.videoteka.service.Security.authenticate(userName, password, pomocniKorisniks);
		if (authenticatedUser != null) {
			setPomocniKorisnik(authenticatedUser);
			nextPage = Index.class;
		} else {
			nextPage = Registration.class;
		}
		
		return nextPage;
	}
    
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

	public void setPomocniKorisnik(PomocniKorisnikI pomocniKorisnik) {
		this.pomocniKorisnik = pomocniKorisnik;
	}

	public PomocniKorisnikI getPomocniKorisnik() {
		return pomocniKorisnik;
	}    
}
